package com.maiji.cloud.controller.shopingmall;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.entities.login.Label;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.shopingmall.*;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseMetaResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.login.LabelResData;
import com.maiji.cloud.response.login.UploadImageResData;
import com.maiji.cloud.response.shopingmall.GoodsParamConfigResData;
import com.maiji.cloud.response.shopingmall.GoodsResData;
import com.maiji.cloud.response.shopingmall.ParamConfigResData;

import com.maiji.cloud.utils.Unlogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/goods/")
@Api(tags = {"商品模块"})
public class GoodsController extends BaseController {

    /**
     *  获取商品列表标签[]
     * @return
     */
    @Unlogin
	@ApiOperation(value = "获取商品列表标签[]")
    @PostMapping("findAllGoodsListLabels")
    public BaseDataResDto<List<LabelResData>> findAllGoodsListLabels () {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/common/findAllLabelsBySource",
                new BaseDataReqDto<Label>().setData(new Label().setSource("商品").setListShow(1)), BaseDataResDto.class);
    }

    /**
     *  获取商品分类标签[]
     * @return
     */
    @Unlogin
	@ApiOperation(value = "获取商品分类标签[]")
    @PostMapping("findAllGoodsClassifyLabels")
    public BaseDataResDto<List<LabelResData>> findAllGoodsClassifyLabels () {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/common/findAllLabelsBySource",
                new BaseDataReqDto<Label>().setData(new Label().setSource("商品").setListShow(2)), BaseDataResDto.class);
    }

    /**
     *  根据商品ID查看商品详情
     * @param baseDataReqDto
     * @return
     */
    @Unlogin
    @ApiOperation(value = "查看商品详情")
    @PostMapping("findGoodsById")
    public BaseDataResDto<GoodsResData> findGoodsById (@RequestBody BaseDataReqDto<String> baseDataReqDto,
                                                       @RequestHeader("maijiToken") String token) {
        return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/goods/findGoodsById", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     *  根据标签ID[]查询商品列表
     * @param baseDataReqDto
     * @return
     */
    @Unlogin
    @PostMapping("findAllGoodsByLabelIds")
    @ApiOperation(value = "根据标签ID[]查询商品列表")
    public BaseMetaResDto<List<GoodsResData>> findAllGoodsByLabelIds(@RequestBody BaseDataReqDto<List<String>> baseDataReqDto,
                                                               @RequestHeader(value="maijiToken",required =false) String maijiToken) {
    	return postForObjectWithToken(maijiToken, REST_URL_SHOPINGMALL + "/goods/findAllGoodsByLabelIds", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     *  获取可积分兑换的商品列表
     * @param baseReqMetaDto
     * @return
     */
    @Unlogin
    @PostMapping("findAllExchangeGoods")
    @ApiOperation(value = "获取可积分兑换的商品列表")
    public BaseMetaResDto<List<GoodsResData>> findAllExchangeGoods(@RequestBody BaseDataReqDto baseReqMetaDto,
                                                           @RequestHeader(value="maijiToken",required =false) String token) {
    	return postForObjectWithToken(token,REST_URL_SHOPINGMALL + "/goods/findAllExchangeGoods", baseReqMetaDto, BaseMetaResDto.class);

    }

    /**
     *  获取积分商城中新品推荐商品列表
     * @param baseReqMetaDto
     * @return
     */
    @Unlogin
    @PostMapping("findAllNewExchangeGoods")
    @ApiOperation(value = "获取积分商城中新品推荐商品列表")
    public BaseMetaResDto<List<GoodsResData>> findAllNewExchangeGoods(@RequestBody BaseDataReqDto baseReqMetaDto,
                                                           @RequestHeader(value="maijiToken",required =false) String token) {
    	return postForObjectWithToken(token,REST_URL_SHOPINGMALL + "/goods/findAllNewExchangeGoods", baseReqMetaDto, BaseMetaResDto.class);

    }

    /**
     *  获取特惠专区商品列表
     * @return
     */
    @Unlogin
    @PostMapping("findAllPreferentialGoods")
    @ApiOperation(value = "获取特惠专区商品列表")
    public BaseMetaResDto<List<GoodsResData>> findAllPreferentialGoods(@RequestHeader(name = "maijiToken", required = false) String token) {
        BaseDataReqDto<String> baseReqMetaDto = new BaseDataReqDto<>();
    	return postForObjectWithToken(token,REST_URL_SHOPINGMALL + "/goods/findAllPreferentialGoods", baseReqMetaDto, BaseMetaResDto.class);
    }

    /**
     *  获取精选热卖商品列表
     * @return
     */
    @Unlogin
    @PostMapping("findAllRecommendGoods")
    @ApiOperation(value = "获取精选热卖商品列表")
    public BaseMetaResDto<List<GoodsResData>> findAllRecommendGoods() {
        return postForObjectWithToken(null,REST_URL_SHOPINGMALL + "/goods/findAllRecommendGoods", new BaseDataReqDto<>(), BaseMetaResDto.class);
    }

    /**
     *  获取新品推荐商品列表
     * @return
     */
    @PostMapping("findAllNewGoods")
    @ApiOperation(value = "获取新品推荐商品列表")
    public BaseMetaResDto<List<GoodsResData>> findAllNewGoods(@RequestHeader("maijiToken") String token) {
        return postForObjectWithToken(token,REST_URL_SHOPINGMALL + "/goods/findAllNewGoods", new BaseDataReqDto<>(), BaseMetaResDto.class);
    }

    /**
     *  商品的收藏或取消收藏
     * @param findByIdReqDto
     * @param token
     * @return
     */
    @PostMapping("collectionGoodsById")
    @ApiOperation(value = "商品的收藏或取消收藏")
    public BaseResDto collectionGoodsById(@RequestBody FindByIdReqDto findByIdReqDto, @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/goods/collectionGoodsById", findByIdReqDto, BaseResDto.class);
    }

    /**
     * 批量删除用户收藏商品（空参为清空收藏）
     * * @param baseDataReqDto
     * @return
     */
    @PostMapping("cancelCollectionGoods")
    @ApiOperation(value = "批量删除用户收藏商品（空参为清空收藏）")
    public BaseResDto cancelCollectionGoods(@RequestBody BaseDataReqDto<List<String>> baseDataReqDto, @RequestHeader("maijiToken") String maijiToken) {
        return postForObjectWithToken(maijiToken, REST_URL_SHOPINGMALL + "/goods/cancelCollectionGoods", baseDataReqDto, BaseResDto.class);
    }

    /**
     *  获取用户收藏商品列表
     * @param baseReqMetaDto
     * @param token
     * @return
     */
    @PostMapping("findAllGoodsCollection")
    @ApiOperation(value = " 获取用户收藏商品列表")
    public BaseMetaResDto<List<GoodsResData>> findAllGoodsCollection(@RequestBody BaseDataReqDto baseReqMetaDto,
                                                               @RequestHeader("maijiToken") String token) {
    	return postForObjectWithToken(token, REST_URL_SHOPINGMALL + "/goods/findAllGoodsCollection", baseReqMetaDto, BaseMetaResDto.class);
    }

    /**
     *  获取商品评论列表标签[]
     * @return
     */        
	 @SuppressWarnings("unchecked")
	@ApiOperation(value = "获取商品评论列表标签[]")
    @PostMapping("findAllReviewLabelBySource")
    public BaseDataResDto<List<Label>> findAllReviewLabelBySource (@RequestHeader("maijiToken") String token) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/common/findAllLabelsBySource",
                new BaseDataReqDto<Label>().setData(new Label().setSource("商品评论").setListShow(1)), BaseDataResDto.class);
    }

    /**
     *  获取麦吉商城轮播图
     * @return
     */
    @PostMapping("findMaijiShoppingMallCarousel")
    @ApiOperation(value = "获取麦吉商城轮播图")
    public BaseDataResDto<List<UploadImageResData>>  findMaijiShoppingMallCarousel (@RequestHeader("maijiToken") String maijiToken) {
        BaseDataReqDto<String> baseDataReqDto = new BaseDataReqDto<>();
        baseDataReqDto.setData("麦吉商城");
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/common/findAppCarousel", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     *  获取个积分商城轮播图
     * @return
     */
    @PostMapping("findIntegralShoppingMallCarousel")
    @ApiOperation(value = "获取个积分商城轮播图")
    public BaseDataResDto<List<UploadImageResData>>  findIntegralShoppingMallCarousel (@RequestHeader("maijiToken") String maijiToken) {
        BaseDataReqDto<String> baseDataReqDto = new BaseDataReqDto<>();
        baseDataReqDto.setData("积分商城");
        return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/common/findAppCarousel", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     *  根据商品名称模糊匹配搜索
     * @return
     */
    @PostMapping("findAllGoodsByName")
    @ApiOperation(value = "根据商品名称模糊匹配搜索")
    public BaseMetaResDto<List<GoodsResData>> findAllGoodsByName(@RequestBody BaseDataReqDto<String> baseDataReqDto,
                                                                 @RequestHeader("maijiToken") String token) {
        return postForObjectWithToken(token,REST_URL_SHOPINGMALL + "/goods/findAllGoodsByName", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     * 根据商品id获得产品参数
     * @param param
     * @return
     */
    @Unlogin
    @PostMapping("getGoodsParamByGoodsId")
    @ApiOperation(value = "根据商品id获得产品参数")
    public BaseDataResDto<List<GoodsParamConfigResData>> getGoodsParamByGoodsId(@RequestBody BaseDataReqDto<String> param){
    	return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/goods/getGoodsParamByGoodsId", param, BaseDataResDto.class);
    }

}
